
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Feign接口有哪些参数？ - 交互式测验</title>
      <style>
        @import url('https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;500;700&display=swap');
        
        body {
          font-family: 'Noto Sans SC', sans-serif;
          background-color: #f4f7f9;
          color: #333;
          display: flex;
          justify-content: center;
          align-items: center;
          min-height: 100vh;
          margin: 0;
          padding: 20px;
          box-sizing: border-box;
        }
        
        .main-wrapper {
            position: relative;
            width: 100%;
            max-width: 900px; /* Wider to accommodate buttons */
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .quiz-container {
          background-color: #ffffff;
          border-radius: 16px;
          box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
          width: 100%;
          max-width: 700px;
          overflow: hidden;
          z-index: 10;
        }

        .quiz-header {
          background-color: #4a90e2;
          color: white;
          padding: 20px 30px;
          text-align: center;
        }

        .quiz-header h1 {
          margin: 0;
          font-size: 24px;
          font-weight: 700;
        }
        
        .quiz-header p {
            margin: 5px 0 0;
            font-size: 14px;
            opacity: 0.9;
        }

        .quiz-body {
          padding: 30px;
        }

        .progress-bar {
            display: none; /* 隐藏进度条 */
            width: 100%;
            background-color: #e0e0e0;
            border-radius: 5px;
            height: 10px;
            margin-bottom: 20px;
        }

        #progress-indicator {
            height: 100%;
            width: 0%;
            background-color: #4caf50;
            border-radius: 5px;
            transition: width 0.3s ease;
        }

        #question-container {
          margin-bottom: 20px;
        }

        #question-text {
          font-size: 18px;
          font-weight: 500;
          line-height: 1.6;
          margin-bottom: 25px;
        }

        .options-list {
          list-style: none;
          padding: 0;
          margin: 0;
        }

        .option-item {
          background-color: #f8f9fa;
          border: 1px solid #dee2e6;
          border-radius: 8px;
          padding: 15px;
          margin-bottom: 12px;
          cursor: pointer;
          transition: background-color 0.2s ease, border-color 0.2s ease;
        }

        .option-item:hover {
          background-color: #e9ecef;
        }
        
        .option-item.selected {
            background-color: #d1e7fd;
            border-color: #4a90e2;
        }

        .quiz-footer {
          padding: 20px 30px;
          display: flex;
          justify-content: space-between; /* 将按钮分布在两侧 */
          align-items: center;
          min-height: 65px; /* Reserve space */
        }

        .nav-btn {
          background-color: #4a90e2;
          color: white;
          border: none;
          border-radius: 8px;
          padding: 10px 20px;
          font-size: 16px;
          font-weight: 500;
          cursor: pointer;
          transition: background-color 0.2s ease, transform 0.2s ease;
          box-shadow: 0 4px 12px rgba(0,0,0,0.15);
        }
        
        #next-btn {
            background-color: #28a745;
        }

        .nav-btn:hover {
          background-color: #357abd;
          transform: scale(1.05);
        }
        
        .nav-btn:disabled {
            background-color: #a0c3e8;
            cursor: not-allowed;
            opacity: 0.7;
        }

        #result-container {
            border-top: 1px solid #eee;
        }
        
        .result-box {
            border-radius: 8px;
            padding: 20px;
            margin-top: 20px;
        }
        
        .result-box.correct {
            background-color: #d4edda;
            border: 1px solid #c3e6cb;
            color: #155724;
        }

        .result-box.incorrect {
            background-color: #f8d7da;
            border: 1px solid #f5c6cb;
            color: #721c24;
        }
        
        .result-box h3 {
            margin-top: 0;
        }

        .explanation-text {
            margin-top: 15px;
            line-height: 1.7;
        }
        
        .source-text {
            font-style: italic;
            font-size: 14px;
            margin-top: 15px;
            color: #555;
        }

        
        .final-score-container {
            padding: 40px;
            text-align: center;
        }
        .final-score-container h2 {
            margin-top: 0;
            margin-bottom: 30px;
        }
        .score-summary {
            display: flex;
            justify-content: center;
            gap: 20px;
            margin-bottom: 40px;
            flex-wrap: wrap;
        }
        .score-card {
            background-color: #f8f9fa;
            border-radius: 12px;
            padding: 20px;
            width: 180px;
            box-shadow: 0 4px 12px rgba(0,0,0,0.05);
            border: 1px solid #e9ecef;
        }
        .score-card h3 {
            margin: 0 0 10px;
            font-size: 16px;
            font-weight: 500;
            color: #555;
        }
        .score-card p {
            margin: 0;
            font-size: 28px;
            font-weight: 700;
            color: #333;
        }
        .score-details table {
            width: 100%;
            font-size: 16px;
        }
        .score-details td {
            padding: 4px 0;
        }
        .score-details td:last-child {
            text-align: right;
            font-weight: 700;
        }
        .report-actions button {
            background-color: #fff;
            border: 1px solid #ccc;
            border-radius: 8px;
            padding: 12px 25px;
            font-size: 16px;
            cursor: pointer;
            margin: 0 10px;
            transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
        }
        .report-actions button:hover {
            background-color: #f1f1f1;
            border-color: #bbb;
            transform: translateY(-2px);
        }
        .report-actions button.primary {
            background-color: #28a745;
            color: white;
            border-color: #28a745;
        }
        .report-actions button.primary:hover {
            background-color: #218838;
        }
        
        .hint-container {
            background-color: #e0f7fa;
            border: 1px solid #b2ebf2;
            border-radius: 8px;
            padding: 15px;
            margin-top: 20px;
            color: #006064;
            font-size: 15px;
            line-height: 1.6;
            display: none; /* 默认隐藏 */
        }
      </style>
    </head>
    <body>
      <div class="main-wrapper">
          <div class="quiz-container">
            <div class="quiz-header">
              <h1>Feign接口有哪些参数？ - 交互式测验</h1>
              <p>检验你对文档内容的理解程度</p>
            </div>
            <div id="quiz-content">
                <div class="quiz-body">
                    <div class="progress-bar">
                        <div id="progress-indicator"></div>
                    </div>
                    <div id="question-container">
                      <p id="question-text"></p>
                      <ul class="options-list" id="options-list"></ul>
                    </div>
                    <div id="result-container"></div>
                    <div id="hint-container" class="hint-container"></div>
                </div>
                <div class="quiz-footer" id="quiz-footer">
                  <button id="prev-btn" class="nav-btn">上一题</button>
                  <button id="hint-btn" class="nav-btn" style="background-color: #ffc107; color: #333; box-shadow: 0 4px 12px rgba(255,193,7,0.3);">提示</button>
                  <button id="next-btn" class="nav-btn">下一题</button>
                </div>
            </div>
          </div>
      </div>

      <script>
        const quizData = [
  {
    "question": "在`@FeignClient`注解中，`fallback`参数的核心作用是什么？",
    "options": [
      "指定服务的URL地址，用于在测试环境中直接连接服务。",
      "指定一个服务降级处理类，当服务调用失败时，执行预定义的降级逻辑以增强系统容错性。",
      "定义一个全局的请求路径前缀，应用于该客户端下的所有接口方法。",
      "指定一个自定义的Feign配置类，用于更精细地控制Feign客户端的行为。"
    ],
    "correctAnswerIndex": 1,
    "explanation": "`fallback`参数用于实现服务熔断降级。它指向一个实现了Feign接口的类，当远程服务调用发生异常或超时，无法正常返回结果时，Feign会调用`fallback`类中对应的方法，返回一个预设的、友好的响应，从而避免了因单个服务故障导致的整个请求链路失败。",
    "source": "文档中「fallback参数」部分",
    "hint": "思考一下，当一个微服务不可用时，系统应该如何优雅地应对以避免雪崩效应？"
  },
  {
    "question": "在使用`@FeignClient`时，`name`（或其别名`value`）参数和`url`参数之间最主要的区别是什么？",
    "options": [
      "`name`用于指定服务在服务注册中心（如Nacos, Eureka）的逻辑名称，而`url`则用于直接指定服务的物理URL地址。",
      "`name`是必填项，而`url`是可选项。",
      "`name`用于标识Bean的名称，而`url`用于配置负载均衡策略。",
      "两者功能完全相同，`url`是`name`的完整写法，推荐使用`url`。"
    ],
    "correctAnswerIndex": 0,
    "explanation": "`name`（或`value`）参数与服务发现机制紧密集成，它指定的是目标服务注册到注册中心的服务ID。Feign会通过负载均衡器从注册中心获取该服务的所有实例并选择一个进行调用。而`url`参数则绕过了服务发现，直接指定了一个硬编码的URL地址，这通常用于开发、测试阶段或调用未注册到中心的服务。",
    "source": "文档中「name参数」和「url参数」部分",
    "hint": "考虑一下微服务架构中，服务实例的地址是动态变化的，我们通常如何找到它们？"
  },
  {
    "question": "根据文档描述，如果一个Feign客户端定义为 `@FeignClient(name = \"user-service\", path = \"/api/v1\")`，并且其接口中有一个方法 `@GetMapping(\"/users/{id}\")`，那么最终构成的请求URL路径部分会是怎样的？",
    "options": [
      "`/users/{id}`，`path`参数会被忽略。",
      "`/api/v1/users/{id}`，`path`参数会作为统一的路径前缀。",
      "`/users/{id}/api/v1`，`path`参数会追加在方法路径之后。",
      "`/api/v1`，方法上定义的路径会被`path`参数覆盖。"
    ],
    "correctAnswerIndex": 1,
    "explanation": "`path`参数用于为Feign客户端下的所有请求定义一个公共的基础路径（context path）。它会被预置在接口方法上定义的具体路径之前，共同构成完整的请求URL路径。这种方式有助于对API进行版本管理或模块划分。",
    "source": "文档中「path参数」部分",
    "hint": "这个参数为接口的所有请求提供了一个共同的“命名空间”或“前缀”。"
  },
  {
    "question": "在`@FeignClient`注解中设置`primary = true`的主要目的是什么？",
    "options": [
      "将该客户端标记为主实例，在负载均衡时拥有最高的请求优先级。",
      "在存在多个相同接口类型的Feign客户端Bean时，将其指定为默认的首选注入对象，以解决依赖注入（@Autowired）时的歧义性问题。",
      "表示该Feign客户端配置为生产环境的主要配置，区别于测试环境。",
      "强制激活该Feign客户端，如果设置为`false`则客户端将处于禁用状态。"
    ],
    "correctAnswerIndex": 1,
    "explanation": "在Spring的依赖注入容器中，如果同一个接口（例如 `SentinelFeign2`）有多个实现或定义的Bean，直接使用 `@Autowired` 会导致不知道该注入哪一个而报错。将其中一个`@FeignClient`设置为 `primary = true`，就等于告诉Spring：“在有多个选择时，请优先注入这一个Bean。”",
    "source": "文档中「primary参数」部分",
    "hint": "当Spring的`@Autowired`发现一个接口有多个可以注入的Bean时，它会如何决策？"
  },
  {
    "question": "根据文档，`@FeignClient`注解中的`value`参数和`name`参数之间存在什么关系？",
    "options": [
      "`value`用于指定具体的值，而`name`用于指定逻辑名称。",
      "`name`的优先级高于`value`，如果同时设置，`value`将被忽略。",
      "`value`是`name`的别名（alias），两者作用完全相同，都用于指定Feign客户端的服务名称。",
      "`value`用于指定服务URL，而`name`用于指定服务ID。"
    ],
    "correctAnswerIndex": 2,
    "explanation": "文档中明确指出，`value`参数的定义与`name`参数相同。在`@FeignClient`注解的源码定义中，`value`上有一个`@AliasFor(\"name\")`注解，这表明它们是彼此的别名，使用任何一个都能达到指定服务名称的效果，两者是完全等价的。",
    "source": "文档中「value参数」和「@FeignClinet注解中的方法」部分",
    "hint": "文档中对`value`参数的定义是：“同`name`参数，用于指定Feign客户端的名称。”"
  },
  {
    "question": "当`@FeignClient`的`decode404`参数设置为`true`时，如果调用的服务端点返回了HTTP 404 (Not Found) 状态码，客户端会发生什么？",
    "options": [
      "客户端会自动触发`fallback`中定义的降级逻辑。",
      "客户端会抛出一个`FeignException.NotFound`异常，中断当前操作。",
      "客户端会将404视为一次正常的、没有找到结果的响应进行处理（通常返回null），而不会抛出异常。",
      "客户端会立即重试该请求，直到获得非404的响应。"
    ],
    "correctAnswerIndex": 2,
    "explanation": "默认情况下，当Feign收到4xx或5xx范围的HTTP状态码时，会抛出`FeignException`。但是，在某些业务场景下，404可能是一种预期的“未找到”结果，而不是一个错误。将`decode404`设置为`true`可以改变这一行为，让Feign正常解码响应体（如果存在）或返回`null`，而不是抛出异常。",
    "source": "文档中「decode404参数」部分",
    "hint": "文档中对该参数的定义是：“指定是否将404错误视为正常响应”。"
  },
  {
    "question": "根据文档开头的描述，当使用Feign接口直接传递一个复杂的Java对象作为参数时（例如 `addUser(User user)`），Feign底层最常见的处理方式是什么？",
    "options": [
      "将对象的每个字段拆分成独立的URL查询参数（`?field1=value1&field2=value2...`）。",
      "将对象序列化为JSON字符串，并将其作为请求体（Request Body）发送。",
      "要求该对象必须是基本数据类型，否则会编译失败。",
      "将对象通过Java序列化转换为二进制流进行传输。"
    ],
    "correctAnswerIndex": 1,
    "explanation": "文档中提到：“直接传递对象，addUser(user)，底层会把对象转成JSON字符串传递”。这通常意味着Feign（结合Spring MVC的注解如`@RequestBody`）会使用内置的消息转换器（如Jackson）将POJO（Plain Old Java Object）序列化为JSON格式，并放入HTTP请求的Body中，以POST或PUT等方式发送给服务端。",
    "source": "文档中「1、feign调用过程中参数的传递的方式」部分",
    "hint": "现代Web API在传输结构化数据时最常用的格式是什么？"
  }
];
        console.log("Quiz Data:", JSON.parse(JSON.stringify(quizData))); // 添加这行用于调试，以可展开的JSON格式输出
        
        let currentQuestionIndex = 0;
        let score = 0;
        // 存储每个问题的回答状态
        const userAnswers = new Array(quizData.length).fill(null); 

        const questionTextEl = document.getElementById('question-text');
        const optionsListEl = document.getElementById('options-list');
        const resultContainerEl = document.getElementById('result-container');
        const quizContentEl = document.getElementById('quiz-content');
        const progressIndicatorEl = document.getElementById('progress-indicator');
        const prevBtn = document.getElementById('prev-btn');
        const nextBtn = document.getElementById('next-btn');
        const hintBtn = document.getElementById('hint-btn');
        const hintContainerEl = document.getElementById('hint-container');

        function loadQuestion() {
          resultContainerEl.innerHTML = '';
          optionsListEl.innerHTML = '';
          hintContainerEl.style.display = 'none'; // 隐藏提示
          
          if (currentQuestionIndex >= quizData.length) {
            showFinalScore();
            return;
          }

          updateProgress();

          const currentQuestion = quizData[currentQuestionIndex];
          questionTextEl.textContent = `(${currentQuestionIndex + 1}/${quizData.length}) ${currentQuestion.question}`;
          
          currentQuestion.options.forEach((optionText, index) => {
            const li = document.createElement('li');
            li.className = 'option-item';
            li.textContent = optionText;
            li.dataset.index = index; // Store index in a data attribute
            // 如果这道题已经回答过，恢复状态
            if (userAnswers[currentQuestionIndex] !== null) {
                if (index === userAnswers[currentQuestionIndex]) {
                    li.classList.add('selected');
                }
            }
            optionsListEl.appendChild(li);
          });

          // 如果已经回答过，直接显示结果
          if (userAnswers[currentQuestionIndex] !== null) {
              const isCorrect = userAnswers[currentQuestionIndex] === currentQuestion.correctAnswerIndex;
              showResult(isCorrect, currentQuestion);
          }
          
          updateNavigationButtons();
          updateProgress();
        }

        function selectOption(optionIndex) {
            userAnswers[currentQuestionIndex] = optionIndex;
            const currentQuestion = quizData[currentQuestionIndex];
            const isCorrect = optionIndex === currentQuestion.correctAnswerIndex;

            // 重新计算分数
            score = userAnswers.reduce((acc, answer, index) => {
                return answer === quizData[index].correctAnswerIndex ? acc + 1 : acc;
            }, 0);

            showResult(isCorrect, currentQuestion);
            updateNavigationButtons();
        }
        
        function updateProgress() {
            const answeredQuestions = userAnswers.filter(answer => answer !== null).length;
            const progressPercentage = (answeredQuestions / quizData.length) * 100;
            progressIndicatorEl.style.width = `${progressPercentage}%`;
        }
        
        function updateNavigationButtons() {
            prevBtn.style.display = 'block';
            nextBtn.style.display = 'block';
            hintBtn.style.display = 'block'; // 显示提示按钮

            prevBtn.disabled = currentQuestionIndex === 0;
            nextBtn.disabled = false; // 最后一题时，下一题按钮不禁用，而是用于显示报告
            nextBtn.textContent = (currentQuestionIndex === quizData.length - 1) ? '查看报告' : '下一题';
            
            // 如果当前问题没有提示，则禁用提示按钮并隐藏提示内容
            if (!quizData[currentQuestionIndex].hint) {
                hintBtn.disabled = true;
                hintContainerEl.style.display = 'none';
                hintContainerEl.textContent = ''; // 清除旧的提示内容
            } else {
                hintBtn.disabled = false;
            }
        }

        function showResult(isCorrect, questionData) {
            resultContainerEl.innerHTML = ''; // 清空之前的结果
            const resultBox = document.createElement('div');
            resultBox.className = `result-box ${isCorrect ? 'correct' : 'incorrect'}`;
            
            let html = `<h3>${isCorrect ? '回答正确！' : '回答错误'}</h3>`;
            if (!isCorrect) {
                html += `<p><strong>正确答案是：</strong> ${questionData.options[questionData.correctAnswerIndex]}</p>`;
            }
            html += `<div class="explanation-text">${questionData.explanation}</div>`;
            html += `<div class="source-text">来源: ${questionData.source}</div>`;
            
            resultBox.innerHTML = html;
            resultContainerEl.appendChild(resultBox);

            // 禁用所有选项的点击事件，并高亮正确/错误答案
            Array.from(optionsListEl.children).forEach((child, index) => {
                child.style.pointerEvents = 'none';
                // 高亮正确答案
                if (index === questionData.correctAnswerIndex) {
                    child.classList.add('correct'); // 需要添加CSS样式
                    child.style.backgroundColor = '#d4edda';
                    child.style.borderColor = '#c3e6cb';
                }
                // 如果选错了，高亮错误选项
                if (!isCorrect && index === userAnswers[currentQuestionIndex]) {
                    child.classList.add('incorrect'); // 需要添加CSS样式
                    child.style.backgroundColor = '#f8d7da';
                    child.style.borderColor = '#f5c6cb';
                }
            });
        }

        function goToNextQuestion() {
            if (currentQuestionIndex < quizData.length - 1) {
                currentQuestionIndex++;
                loadQuestion();
            } else {
                showFinalScore();
            }
        }

        function goToPreviousQuestion() {
            if (currentQuestionIndex > 0) {
                currentQuestionIndex--;
                loadQuestion();
            }
        }
        
        function showHint() {
            const currentQuestion = quizData[currentQuestionIndex];
            if (currentQuestion.hint) {
                hintContainerEl.textContent = currentQuestion.hint;
                hintContainerEl.style.display = 'block';
            } else {
                hintContainerEl.style.display = 'none';
            }
        }

        function showFinalScore() {
            document.querySelector('.quiz-body').style.display = 'none';
            document.getElementById('quiz-footer').style.display = 'none';

            const correctCount = score;
            const totalQuestions = quizData.length;
            const answeredCount = userAnswers.filter(a => a !== null).length;
            const wrongCount = answeredCount - correctCount;
            const skippedCount = totalQuestions - answeredCount;
            const accuracy = totalQuestions > 0 ? Math.round((correctCount / totalQuestions) * 100) : 0;
            const errorRate = totalQuestions > 0 ? Math.round((wrongCount / totalQuestions) * 100) : 0;

            const finalScoreHtml =
                '<div class="final-score-container">' +
                '<h2>答题报告</h2>' +
                '<div class="score-summary">' +
                '<div class="score-card">' +
                '<h3>得分</h3>' +
                '<p>' + correctCount + ' / ' + totalQuestions + '</p>' +
                '</div>' +
                '<div class="score-card">' +
                '<h3>正确率</h3>' +
                '<p>' + accuracy + '%</p>' +
                '</div>' +
                '<div class="score-card">' +
                '<h3>错误率</h3>' +
                '<p>' + errorRate + '%</p>' +
                '</div>' +
                '<div class="score-card score-details">' +
                '<table>' +
                '<tr><td>正确</td><td>' + correctCount + '</td></tr>' +
                '<tr><td>错误</td><td>' + wrongCount + '</td></tr>' +
                '<tr><td>未答</td><td>' + skippedCount + '</td></tr>' +
                '</table>' +
                '</div>' +
                '</div>' +
                '<div class="report-actions">' +
                '<button id="review-btn">回顾测验</button>' +
                '<button class="primary" onclick="location.reload()">再试一次</button>' +
                '</div>' +
                '</div>';

            let reportEl = document.querySelector('.final-score-container');
            if (reportEl) {
                reportEl.remove();
            }
            quizContentEl.insertAdjacentHTML('beforeend', finalScoreHtml);
            document.getElementById('review-btn').addEventListener('click', reviewQuiz);
        }

        function reviewQuiz() {
            const reportEl = document.querySelector('.final-score-container');
            if (reportEl) {
                reportEl.remove();
            }

            document.querySelector('.quiz-body').style.display = 'block';
            document.getElementById('quiz-footer').style.display = 'flex';
            
            currentQuestionIndex = 0;
            loadQuestion();
            updateNavigationButtons(); // Ensure nav buttons are correctly displayed
        }

        // Event Delegation for options
        optionsListEl.addEventListener('click', (event) => {
            if (event.target && event.target.matches('li.option-item')) {
                // Check if the question has already been answered
                if (userAnswers[currentQuestionIndex] === null) {
                    const selectedIndex = parseInt(event.target.dataset.index, 10);
                    selectOption(selectedIndex);
                }
            }
        });

        prevBtn.addEventListener('click', goToPreviousQuestion);
        nextBtn.addEventListener('click', goToNextQuestion);
        hintBtn.addEventListener('click', showHint);
        
        // 初始加载
        loadQuestion();
      </script>
    </body>
    </html>
  